home *** CD-ROM | disk | FTP | other *** search
Text File | 1992-09-02 | 8.5 KB | 246 lines | [TEXT/CCL2] |
- ;;; pop-up-select-icon-view.lisp
- ;;;
- ;;; Paul McCartney, Spring 1992
- ;;;
- ;;; Copyright © 1992 Paul McCartney. All Rights Reserved.
- ;;;
- ;;; Washington University Medical Informatics Training Program
- ;;;
- ;;; DESCRIPTION:
- ;;;
- ;;; This is a specialization of pop up view. Inside of a pop up view,
- ;;; a palette of icons are drawn. The user can select an icon by moving
- ;;; the mouse to it. The identifier of the selected icon is returned.
- ;;;
- ;;; USE:
- ;;;
- ;;; pop-up-select-icon-view - object class, DO NOT INSTALL THIS AS A VIEW.
- ;;; :icons - list consisting of one of the following:
- ;;; 1) icon resource ID or handle (color-p = nil)
- ;;; 2) cicn resource ID or handle (color-p = t)
- ;;; 3) list: (<ID or handle> <nickname>)
- ;;; :icon-size - icon encoded point size
- ;;; :max-column - max number of icons displayed side by side before
- ;;; starting a new row
- ;;; :color-p - color icons (cicn resource) or bw icons (icon resource)
- ;;; :color-list - same as pop up view
- ;;;
- ;;; puv-select-icon - called in response to a click event, this displays
- ;;; the icon palette
- ;;;
- ;;; pusiv-destroy - dispose icon data
- ;;;
- ;;; HISTORY:
- ;;;
- ;;; 7/21/92 Created. - PM
- ;;;
-
- (in-package :ccl)
-
- (require :pop-up-view)
-
- (export '(pop-up-select-icon-view puv-select-icon pusiv-destroy)
- :ccl)
-
-
- (defclass pop-up-select-icon-view (pop-up-view)
- ((icons :initarg :icons :accessor icons)
- (icon-nicknames :accessor icon-nicknames)
- (icon-size :initarg :icon-size :accessor i-size)
- (max-column :initarg :max-column :accessor max-col)
- (separation :initarg :separation :accessor gap)
- (color-p :initarg :color-p :accessor color-p))
- (:default-initargs
- :icons ()
- :icon-size #@(16 16)
- :max-column 5
- :separation 7
- :color-p t
- )
- )
-
-
- (defmethod initialize-instance ((pusiv pop-up-select-icon-view) &rest initargs)
- (apply #'call-next-method pusiv initargs)
-
- (setf (draw-fn pusiv)
- #'(lambda (view size data)
- (declare (ignore view size data))
- (puv-draw-icons pusiv)))
-
- (let ((nicknames ())
- (icons ()))
- (dolist (icon (icons pusiv))
- (cond ((listp icon)
- (push (first icon) icons)
- (push (second icon) nicknames))
- (t (push icon icons))))
- (setf (icon-nicknames pusiv) nicknames)
- (setf (icons pusiv) icons))
-
- (let ((i-handles ()))
- (dolist (icon (icons pusiv) (setf (icons pusiv) (nreverse i-handles)))
- (unless (or (typep icon 'fixnum) (pointerp icon))
- (error "~s is not a valid icon (not a resource-id or pointer)."))
- (cond ((typep icon 'fixnum)
- (let ((i-handle (if (color-p pusiv)
- (#_getCicon icon)
- (#_geticon icon))))
- (if (%null-ptr-p i-handle)
- (error "no icon resource with id ~s." icon)
- (push i-handle i-handles))))
- (t (push icon i-handles))) ))
-
- (let* ((n-icons (length (icons pusiv)))
- (rows (ceiling n-icons (max-col pusiv)))
- (cell-size-h (+ (gap pusiv) (point-h (i-size pusiv))))
- (cell-size-v (+ (gap pusiv) (point-v (i-size pusiv))))
- (width (if (< n-icons (max-col pusiv))
- n-icons
- (max-col pusiv))))
- (setf (size pusiv)
- (make-point (+ (* cell-size-h width) (gap pusiv) 2)
- (+ (* cell-size-v rows) (gap pusiv) 2))) ))
-
-
- (defmethod pusiv-destroy ((pusiv pop-up-select-icon-view))
- (if (color-p pusiv)
- (dolist (icon (icons pusiv))
- (#_DisposCIcon icon))) )
-
-
- (defmethod puv-select-icon ((pusiv pop-up-select-icon-view) view)
- (let* ((pop-up-view (puv-store-onscreen-view *puv-info*))
- (user-selected-icon nil)
- (old-pen-size (pref (wptr view) windowRecord.pnsize))
- (window-view (view-window view)))
- (copy-background-offscreen window-view (size pusiv))
- (puv-draw pusiv pop-up-view nil)
- (with-port (wptr view) (#_PenSize :long #@(3 3)))
- (setf user-selected-icon (puv-user-choose-icon pusiv pop-up-view))
- (with-port (wptr view) (#_PenSize :long old-pen-size))
- (restore-background window-view)
- user-selected-icon ))
-
-
- (defmethod puv-user-choose-icon ((pusiv pop-up-select-icon-view) view)
- (let (choice)
- (with-focused-view view
- (do* ((old-topleft -100)
- (old-bottomright -100)
- (draw-state 'drawn)
- (cell-size-h (+ (gap pusiv) (point-h (i-size pusiv))))
- (cell-size-v (+ (gap pusiv) (point-v (i-size pusiv))))
- (pos (view-mouse-position view) (view-mouse-position view))
- (column (floor (point-h pos) cell-size-h)
- (floor (point-h pos) cell-size-h))
- (row (floor (point-v pos) cell-size-v)
- (floor (point-v pos) cell-size-v))
- (topleft (make-point (- (+ (gap pusiv) (* column cell-size-h)) 3)
- (- (+ (gap pusiv) (* row cell-size-v)) 3))
- (make-point (- (+ (gap pusiv) (* column cell-size-h)) 3)
- (- (+ (gap pusiv) (* row cell-size-v)) 3)))
- (bottomright (add-points topleft (make-point (1- cell-size-h) (1- cell-size-v)))
- (add-points topleft (make-point (1- cell-size-h) (1- cell-size-v)))))
- ((not (mouse-down-p)))
-
- (setf choice (+ column (* row (max-col pusiv))))
-
- (when (and (or (/= topleft old-topleft) (/= bottomright old-bottomright))
- (eq draw-state 'drawn))
- (with-port (wptr view) (#_PenMode #$srcXor))
- (with-fore-color *red-color*
- (rlet ((r :rect :topleft old-topleft :bottomright old-bottomright))
- (#_FrameRect r)))
- (with-port (wptr view) (#_PenMode #$srcCopy))
- (setf draw-state 'erased))
- (when (and (<= 0 column (1- (max-col pusiv)))
- (<= 0 choice (1- (length (icons pusiv))))
- (eq draw-state 'erased))
- (with-port (wptr view) (#_PenMode #$srcXor))
- (with-fore-color *black-color*
- (rlet ((r :rect :topleft topleft :bottomright bottomright))
- (#_FrameRect r)))
- (with-port (wptr view) (#_PenMode #$srcCopy))
- (setf draw-state 'drawn)
- (setf old-topleft topleft)
- (setf old-bottomright bottomright) )) )
-
- (if (<= 0 choice (1- (length (icons pusiv))))
- (if (>= (1- (length (icon-nicknames pusiv))) choice)
- (nth choice (icon-nicknames pusiv))
- choice)
- nil) ))
-
-
- (defmethod puv-draw-icons ((pusiv pop-up-select-icon-view))
- (let ((cell-size-h (+ (gap pusiv) (point-h (i-size pusiv))))
- (cell-size-v (+ (gap pusiv) (point-v (i-size pusiv))))
- (offset (make-point (ceiling (gap pusiv) 2) (ceiling (gap pusiv) 2))))
- (dotimes (n (length (icons pusiv)))
- (let* ((icon (nth n (icons pusiv)))
- (row (floor n (max-col pusiv)))
- (column (- n (* row (max-col pusiv))))
- (topleft (make-point (+ (gap pusiv) (* column cell-size-h))
- (+ (gap pusiv) (* row cell-size-v))))
- (bottomright (add-points topleft (i-size pusiv))))
-
- (rlet ((r :rect :topleft topleft :bottomright bottomright)
- (r1 :rect
- :topleft (subtract-points topleft offset)
- :bottomright (add-points bottomright offset)))
- (if (color-p pusiv)
- (#_plotCicon r icon)
- (#_ploticon r icon))
- (#_framerect r1))) )))
-
-
- (provide :pop-up-select-icon-view)
-
-
- #|
- ; Example
-
- (require :quickdraw)
-
- (puv-init)
- ;(puv-destroy)
-
- (defclass foo-window (window)
- ()
- (:default-initargs
- :view-size #@(300 300)
- :color-p t
- )
- )
-
- (defvar *bw-pusiv*)
-
- (setf *bw-pusiv*
- (make-instance 'pop-up-select-icon-view
- :color-p nil
- :icon-size #@(32 32)
- :icons '(0 1 2 0)
- :max-column 2
- :color-list (list :background *yellow-color*
- :frame *light-blue-color*
- :shadow *blue-color*)))
-
- (defmethod view-draw-contents ((view foo-window))
- (dotimes (i 60)
- (with-fore-color (random most-positive-fixnum)
- (move-to view 10 (+ 20 (* i 2)))
- (line-to view 100 (+ 20 (* i 4)))))
- (move-to view 10 20)
- (format view "Click here."))
-
- (defmethod view-click-event-handler ((view foo-window) where)
- (declare (ignore where))
- (let ((selection (puv-select-icon *bw-pusiv* view)))
- (if selection
- (dotimes (i (1+ selection))
- (ed-beep)))))
-
- (setf w (make-instance 'foo-window))
- |#
-